<template>
  <div> 
    <el-tabs v-model="mediaType" type="card" @tab-click="handleTabClick">
      <el-tab-pane :label="releaseCheckNum.weixin" name="wechat"></el-tab-pane>
      <el-tab-pane :label="releaseCheckNum.sms" name="sms"></el-tab-pane>
      <el-tab-pane :label="releaseCheckNum.mail" name="mail"></el-tab-pane>
      <el-tab-pane :label="releaseCheckNum.wepage" name="wepage"></el-tab-pane>
      <el-tab-pane :label="releaseCheckNum.poster" name="poster"></el-tab-pane>
    </el-tabs>
    <wechat-check v-if="mediaType=='wechat'"></wechat-check>
    <weibo-check v-else-if="mediaType=='weibo'"></weibo-check>
    <sms-check v-else-if="mediaType=='sms'"></sms-check>
    <mail-check v-else-if="mediaType=='mail'"></mail-check>
    <wepage-check v-else-if="mediaType=='wepage'"></wepage-check>
    <poster-check v-else="mediaType=='poster'"></poster-check>
  </div>
</template>
<script>
  import wechatCheck from './wechat'
  import weiboCheck from './weibo'
  import smsCheck from './sms'
  import mailCheck from './mail'
  import wepageCheck from './wepage'
  import {mapActions} from 'vuex'
  import eventBus from '@/components/common/eventBus'
  import posterCheck from './poster'
  export default {
    components: {wechatCheck, weiboCheck, smsCheck, mailCheck, wepageCheck, posterCheck},
    data () {
      return {
        releaseCheckNum: {
          weixin: '微信(0)',
          sms: '短信(0)',
          mail: '邮件(0)',
          wepage: '微页面(0)',
          poster: '海报(0)'
        },
        mediaType: this.$route.params.mediaType
      }
    },
    mounted () {
      this.init()
    },
    methods: {
      ...mapActions(['getReleaseCheckNum']),
      init () {
        eventBus.$on('getReleaseCheckNum', () => {
          this.getReleaseCheckNum().then(res => {
            let dat = res.data
            if (dat.code === 1 && !this.$_.isEmpty(dat.data)) {
              this.releaseCheckNum.weixin = `微信(${dat.data['1']})`
              this.releaseCheckNum.sms = `短信(${dat.data['3']})`
              this.releaseCheckNum.mail = `邮件(${dat.data['4']})`
              this.releaseCheckNum.wepage = `微页面(${dat.data['5']})`
              this.releaseCheckNum.poster = `海报(${dat.data['7']})`
            }
          })
        })
        eventBus.$emit('getReleaseCheckNum')
      },
      handleTabClick () {
        this.$router.push({name: 'ReleaseCheck', params: {mediaType: this.mediaType}})
      }
    }
  }
</script>
